package com.airline.service;

import com.airline.dao.FlightDAO;
import com.airline.dao.FlightStockDAO;
import com.airline.entity.Flight;
import com.airline.entity.FlightStock;

import java.math.BigDecimal;
import java.util.List;

public class FlightService {
    private final FlightDAO flightDAO = new FlightDAO();
    private final FlightStockService stockService = new FlightStockService(); // 余票服务

    /**
     * 查询所有航班
     */
    public List<Flight> getAllFlights() {
        return flightDAO.findAll();
    }

    /**
     * 按航班号查询单个航班
     */
    public Flight getFlightByNo(String flightNo) {
        return flightDAO.findByFlightNo(flightNo);
    }

    /**
     * 判断航班是否存在
     */
    public boolean existsFlight(String flightNo) {
        return flightDAO.existsFlight(flightNo);
    }

    /**
     * 按条件筛选航班
     */
    public List<Flight> findFlightsByCondition(String departure, String destination,
                                               BigDecimal minPrice, BigDecimal maxPrice) {
        return flightDAO.findByCondition(departure, destination, minPrice, maxPrice);
    }

    /**
     * 新增：查询航班余票（供Main.java展示）
     */
    public FlightStock getFlightStockByNo(String flightNo) {
        return stockService.getStockByFlightNo(flightNo);
    }
}